//============================================================
// Function   : Create a Singleton Application
// Author     : Akui
// Date       : 04/25/2009
// URL        : http://www.codeproject.com/KB/dialog/single_instance.aspx
// How to use :	(1) Include "SingleInstance.h"
//              (2) Declare a global CSigleInstance object
//				(3) After the main window handle is valid, call SetWindow to store it
//============================================================
#ifndef	SINGLEINSTANCE_H
#define	SINGLEINSTANCE_H

const TCHAR	TAG[]=_T("__AKUI__");

class CSingleInstance 
{
private:
	//file mapping handle
	HANDLE m_hMap;			
	//file mapping unique name
	LPTSTR m_pszUniqueName;	

public:
	CSingleInstance(LPCTSTR pszUniqueName=NULL, int nCmdShow=SW_RESTORE);
	~CSingleInstance();
	//store main window handle for later ones to active me
	void SetWindow(HWND hWnd);

private:
	//find the running instance, and get its main window handle
	//phWnd : the window handle
	//return value : true if found a running instance
	BOOL GetPrevInstance(HWND *phWnd);
	//create file mapping
	void CreateMap();
};

#endif